﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.BUSINESSLAYER
{
    public class DiasHorario
    {
        public List<TDiasHorario> ListarTodas(int idHorario)
        {
            masterDBACEntities db = new masterDBACEntities();
            var empre = from d in db.TDiasHorario where d.idHorario == idHorario select d;
            return empre.ToList();
        }

        public void Agregar(int idHorario, int dia, string horaEntrada, string horaSalida, string Observa)
        {
            try
            {
                masterDBACEntities db = new masterDBACEntities();
                TDiasHorario td = new TDiasHorario()
                {
                    idHorario = idHorario,
                    dia = (byte?)dia,
                    entrada = horaEntrada,
                    salida = horaSalida,
                    ObservacionesDia = Observa
                };
                db.AddToTDiasHorario(td);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
            
        }

        public void Modificar(int idT, int idHorario, int dia, string horaEntrada, string horaSalida, string Observa)
        {
            masterDBACEntities db = new masterDBACEntities();
            TDiasHorario  th = db.TDiasHorario.FirstOrDefault(c => c.idDiasHorario == idT);
            if (th != null)
            {
                th.dia = (byte?) dia;
                th.entrada = horaEntrada;
                th.salida = horaSalida;
                th.ObservacionesDia = Observa;
                db.SaveChanges();
            }
        }
        public void Eliminar(int idT)
        {
            masterDBACEntities db = new masterDBACEntities();
            TDiasHorario  th = db.TDiasHorario.FirstOrDefault(c => c.idDiasHorario == idT);
            if (th != null)
            {
                db.TDiasHorario.DeleteObject(th);
                db.SaveChanges();
            }

        }
    }
}
